using PageFlowQuickstart.Modules.Customers.BusinessEntities;
using PageFlowQuickstart.Modules.Customers.Tests.Mocks;
using PageFlowQuickstart.Modules.Customers.Views;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PageFlowQuickstart.Modules.Customers.Tests.Views.Mocks;

namespace PageFlowQuickstart.Modules.Customers.Tests.Views
{
    [TestClass]
    public class SummaryViewPresenterFixture
    {
        [TestMethod]
        public void OnViewInitializedCallsControllerCurrentCustomerAndViewSetCustomerAndControllerFinishApproval()
        {
            MockCustomersController controller = new MockCustomersController();
            Customer customer = controller.InnerCurrentCustomer = new Customer();
            SummaryViewPresenter presenter = new SummaryViewPresenter(controller);
            MockSummaryView view = new MockSummaryView();
            presenter.View = view;

            presenter.OnViewInitialized();

            Assert.IsTrue(controller.CurrentCustomerRetrieved);
            Assert.IsTrue(view.CustomerSet);
            Assert.AreSame(customer, view.Customer);
            Assert.IsTrue(controller.FinishCustomerApprovalCalled);
        }

        [TestMethod]
        public void OnApproveAnotherCustomerCallsStartCustomerApproval()
        {
            MockCustomersController controller = new MockCustomersController();
            SummaryViewPresenter presenter = new SummaryViewPresenter(controller);
            MockSummaryView view = new MockSummaryView();
            presenter.View = view;

            presenter.OnApproveAnotherCustomer();

            Assert.IsTrue(controller.StartCustomersApprovalCalled);
        }
    }

    namespace Mocks
    {
        internal class MockSummaryView : ISummaryView
        {
            private Customer _customer;
            public bool CustomerSet = false;

            #region ISummaryView Members

            public Customer Customer
            {
                get { return _customer; }
                set
                {
                    _customer = value;
                    CustomerSet = true;
                }
            }

            #endregion
        }
    }
}
